﻿using AutoMapper;
using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.Domain.zyy;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Writer.API.Appliaction.Commends.Zyy;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Writer.API.Appliaction.CommandHandlers.Zyy
{
    public class DeleteShelfdictionaryHandler : IRequestHandler<DeleteShelfdictionaryCommand, ApiResult<int>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public DeleteShelfdictionaryHandler(IMapper mapper,ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }

        public async Task<ApiResult<int>> Handle(DeleteShelfdictionaryCommand request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<int> result = new ApiResult<int>();

                var del = await db.Queryable<Shelfdictionary>().FirstAsync(p => p.ShelfId == request.ShelfId);
                del.IsDelete = true;
                var res = await db.Updateable<Shelfdictionary>(del).ExecuteCommandAsync();
                if (res > 0)
                {
                    result.Code = ApiEnums.删除成功;
                    result.Msg = "删除成功";
                }
             
                else
                {
                    result.Code = ApiEnums.删除失败;
                    result.Msg = "删除失败";
                }
                return result;
            }
            catch (Exception)
            {

                throw;
            }
           
          
        }
    }
}
